﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentGain.model;
using DocumentGain;

namespace DocumentGain.dal
{
    public class Service
    {


        private string ConvertString(string str)
        {
            //return str.Replace("&nbsp;", "").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&")
            //    .Replace("&quot;", "\"").Replace("&apos;", "'").Replace("&cent;", "￠").Replace("&pound;", "£")
            //    .Replace("&yen;", "¥").Replace("&sect;", "§").Replace("&copy;", "©").Replace("&reg;", "®")
            //    .Replace("&times;", "×").Replace("&divide;", "÷").Replace("<p>", "").Replace("</p>", "");

            return str.Replace("'", "\"");
        }
        //public void AddMainDocument(string key)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("insert into MainDocument(DocumentID) values ('" + key + "')");
        //    sqlHelp.ExecuteSql(strSql.ToString());
        //}

        public int AddWHRT_Attachment(WHRT_Attachment model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.Id != null)
            {
                strSql1.Append("Id,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.pid != null)
            {
                strSql1.Append("pid,");
                strSql2.Append("'" + model.pid + "',");
            }
            if (model.fileid != null)
            {
                strSql1.Append("fileid,");
                strSql2.Append("'" + model.fileid + "',");
            }
            if (model.filename != null)
            {
                strSql1.Append("filename,");
                strSql2.Append("'" + model.filename + "',");
            }
            if (model.fileType != null)
            {
                strSql1.Append("fileType,");
                strSql2.Append("'" + model.fileType + "',");
            }
            if (model.historyDataId != null)
            {
                strSql1.Append("historyDataId,");
                strSql2.Append("'" + model.historyDataId + "',");
            }
            if (model.orderNo != null)
            {
                strSql1.Append("orderNo,");
                strSql2.Append("" + model.orderNo + ",");
            }
            if (model.filesize != null)
            {
                strSql1.Append("filesize,");
                strSql2.Append("" + model.filesize + ",");
            }
            strSql.Append("insert into WHRT_Attachment(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpIcanYunPan.ExecuteSql(strSql.ToString());
        }

        public void AddAuditing(Auditing model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Auditing(");
            strSql.Append("AuditingID,DocumentID,[User],date,opinion,status,num");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.AuditingID + "',");
            strSql.Append("'" + model.DocumentID + "',");
            strSql.Append("'" + model.User + "',");
            strSql.Append("'" + model.date + "',");
            strSql.Append("'" + model.opinion + "',");
            strSql.Append("'" + model.status + "',");
            if (model.num == null)
            {
                model.num = 0;
            }
            strSql.Append("" + model.num + "");
            strSql.Append(")");
            sqlHelp.ExecuteSql(strSql.ToString());
        }

        public void AddRules(Rules model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Rules(");
            strSql.Append("RulesID,DocumentID,manager,docmanager,readuser,todouser");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.RulesID + "',");
            strSql.Append("'" + model.DocumentID + "',");
            strSql.Append("'" + model.manager + "',");
            strSql.Append("'" + model.docmanager + "',");
            strSql.Append("'" + model.readuser + "',");
            strSql.Append("'" + model.todouser + "'");
            strSql.Append(")");
            sqlHelp.ExecuteSql(strSql.ToString());
        }

        public void AddFile(File model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.fileID != null)
            {
                strSql1.Append("fileID,");
                strSql2.Append("'" + model.fileID + "',");
            }
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.filename != null)
            {
                strSql1.Append("filename,");
                strSql2.Append("'" + model.filename + "',");
            }
            if (model.filepath != null)
            {
                strSql1.Append("filepath,");
                strSql2.Append("'" + model.filepath + "',");
            }
            if (model.isEditor != null)
            {
                strSql1.Append("isEditor,");
                strSql2.Append("" + (model.isEditor ? 1 : 0) + ",");
            }
            if (model.flagftype != null)
            {
                strSql1.Append("flagftype,");
                strSql2.Append("'" + model.flagftype + "',");
            }
            if (model.flagfix != null)
            {
                strSql1.Append("flagfix,");
                strSql2.Append("'" + model.flagfix + "',");
            }
            if (model.fixrecord != null)
            {
                strSql1.Append("fixrecord,");
                strSql2.Append("'" + model.fixrecord + "',");
            }
            strSql.Append("insert into [File](");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");

            sqlHelp.ExecuteSql(strSql.ToString());
        }

        public void AddTabulation(Tabulation model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Tabulation(");
            strSql.Append("TabulationID,DocumentID,name,cname,value");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.TabulationID + "',");
            strSql.Append("'" + model.DocumentID + "',");
            strSql.Append("'" + model.name + "',");
            strSql.Append("'" + model.cname + "',");

            if (model.value != null)
            {
                strSql.Append("'" + ConvertString(model.value) + "'");
            }
            else
            {
                strSql.Append("'" + model.value + "'");
            }

            
            strSql.Append(")");
            sqlHelp.ExecuteSqlEx(strSql.ToString());
        }

        public void AddAuditingRecord(AuditingRecord model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into AuditingRecord(");
            strSql.Append("AuditingRecordID,DocumentID,[User],date,status,num");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.AuditingRecordID + "',");
            strSql.Append("'" + model.DocumentID + "',");
            strSql.Append("'" + model.User + "',");
            strSql.Append("'" + model.date + "',");
            strSql.Append("'" + model.status + "',");
            strSql.Append("" + model.num + "");
            strSql.Append(")");
            sqlHelp.ExecuteSql(strSql.ToString());
        }

        public void AddMainDocument(MainDocument model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.dbpath != null)
            {
                strSql1.Append("dbpath,");
                strSql2.Append("'" + model.dbpath + "',");
            }
            if (model.qicaorq != null)
            {
                strSql1.Append("qicaorq,");
                strSql2.Append("'" + model.qicaorq + "',");
            }
            if (model.flowtype != null)
            {
                strSql1.Append("flowtype,");
                strSql2.Append("'" + model.flowtype + "',");
            }
            if (model.DocumentType != null)
            {
                strSql1.Append("DocumentType,");
                strSql2.Append("'" + model.DocumentType + "',");
            }
            strSql.Append("insert into MainDocument(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            sqlHelp.ExecuteSql(strSql.ToString());
        }

        public int AddInstanceContext(SF_InstanceContext model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.ObjectID != null)
            {
                strSql1.Append("ObjectID,");
                strSql2.Append("'" + model.ObjectID + "',");
            }
            if (model.Approval != null)
            {
                strSql1.Append("Approval,");
                strSql2.Append("" + model.Approval + ",");
            }
            if (model.BinParameterTable != null)
            {
                strSql1.Append("BinParameterTable,");
                strSql2.Append("" + model.BinParameterTable + ",");
            }
            if (model.BinParentDataMaps != null)
            {
                strSql1.Append("BinParentDataMaps,");
                strSql2.Append("" + model.BinParentDataMaps + ",");
            }
            if (model.CreatedTime != null)
            {
                strSql1.Append("CreatedTime,");
                strSql2.Append("'" + model.CreatedTime + "',");
            }
            if (model.CurrentWaitingReplyID != null)
            {
                strSql1.Append("CurrentWaitingReplyID,");
                strSql2.Append("" + model.CurrentWaitingReplyID + ",");
            }
            if (model.CustomCost1 != null)
            {
                strSql1.Append("CustomCost1,");
                strSql2.Append("" + model.CustomCost1 + ",");
            }
            if (model.CustomCost1Rate != null)
            {
                strSql1.Append("CustomCost1Rate,");
                strSql2.Append("" + model.CustomCost1Rate + ",");
            }
            if (model.CustomCost2 != null)
            {
                strSql1.Append("CustomCost2,");
                strSql2.Append("" + model.CustomCost2 + ",");
            }
            if (model.CustomCost2Rate != null)
            {
                strSql1.Append("CustomCost2Rate,");
                strSql2.Append("" + model.CustomCost2Rate + ",");
            }
            if (model.CustomCost3 != null)
            {
                strSql1.Append("CustomCost3,");
                strSql2.Append("" + model.CustomCost3 + ",");
            }
            if (model.CustomCost3Rate != null)
            {
                strSql1.Append("CustomCost3Rate,");
                strSql2.Append("" + model.CustomCost3Rate + ",");
            }
            if (model.CustomCost4 != null)
            {
                strSql1.Append("CustomCost4,");
                strSql2.Append("" + model.CustomCost4 + ",");
            }
            if (model.CustomCost4Rate != null)
            {
                strSql1.Append("CustomCost4Rate,");
                strSql2.Append("" + model.CustomCost4Rate + ",");
            }
            if (model.CustomCost5 != null)
            {
                strSql1.Append("CustomCost5,");
                strSql2.Append("" + model.CustomCost5 + ",");
            }
            if (model.CustomCost5Rate != null)
            {
                strSql1.Append("CustomCost5Rate,");
                strSql2.Append("" + model.CustomCost5Rate + ",");
            }
            if (model.EstimatedFinishTime != null)
            {
                strSql1.Append("EstimatedFinishTime,");
                strSql2.Append("'" + model.EstimatedFinishTime + "',");
            }
            if (model.Exceptional != null)
            {
                strSql1.Append("Exceptional,");
                strSql2.Append("" + model.Exceptional + ",");
            }
            if (model.ExternalPrimaryKey != null)
            {
                strSql1.Append("ExternalPrimaryKey,");
                strSql2.Append("'" + model.ExternalPrimaryKey + "',");
            }
            if (model.ExternalPrimaryValue != null)
            {
                strSql1.Append("ExternalPrimaryValue,");
                strSql2.Append("'" + model.ExternalPrimaryValue + "',");
            }
            if (model.ExternalTableName != null)
            {
                strSql1.Append("ExternalTableName,");
                strSql2.Append("'" + model.ExternalTableName + "',");
            }
            if (model.FinalTokenId != null)
            {
                strSql1.Append("FinalTokenId,");
                strSql2.Append("" + model.FinalTokenId + ",");
            }
            if (model.FinishTime != null)
            {
                strSql1.Append("FinishTime,");
                strSql2.Append("'" + model.FinishTime + "',");
            }
            if (model.HumanCost != null)
            {
                strSql1.Append("HumanCost,");
                strSql2.Append("" + model.HumanCost + ",");
            }
            if (model.HumanCostRate != null)
            {
                strSql1.Append("HumanCostRate,");
                strSql2.Append("" + model.HumanCostRate + ",");
            }
            if (model.InitiativeTokenId != null)
            {
                strSql1.Append("InitiativeTokenId,");
                strSql2.Append("" + model.InitiativeTokenId + ",");
            }
            if (model.InstanceName != null)
            {
                strSql1.Append("InstanceName,");
                strSql2.Append("'" + model.InstanceName + "',");
            }
            if (model.IsChildInstance != null)
            {
                strSql1.Append("IsChildInstance,");
                strSql2.Append("" + model.IsChildInstance + ",");
            }
            if (model.LastActiveTime != null)
            {
                strSql1.Append("LastActiveTime,");
                strSql2.Append("'" + model.LastActiveTime + "',");
            }
            if (model.MachineCost != null)
            {
                strSql1.Append("MachineCost,");
                strSql2.Append("" + model.MachineCost + ",");
            }
            if (model.MachineCostRate != null)
            {
                strSql1.Append("MachineCostRate,");
                strSql2.Append("" + model.MachineCostRate + ",");
            }
            if (model.ManagementCost != null)
            {
                strSql1.Append("ManagementCost,");
                strSql2.Append("" + model.ManagementCost + ",");
            }
            if (model.ManagementCostRate != null)
            {
                strSql1.Append("ManagementCostRate,");
                strSql2.Append("" + model.ManagementCostRate + ",");
            }
            if (model.MaterialCost != null)
            {
                strSql1.Append("MaterialCost,");
                strSql2.Append("" + model.MaterialCost + ",");
            }
            if (model.MaterialCostRate != null)
            {
                strSql1.Append("MaterialCostRate,");
                strSql2.Append("" + model.MaterialCostRate + ",");
            }
            if (model.MessageEmergency != null)
            {
                strSql1.Append("MessageEmergency,");
                strSql2.Append("" + model.MessageEmergency + ",");
            }
            if (model.NextTokenId != null)
            {
                strSql1.Append("NextTokenId,");
                strSql2.Append("" + model.NextTokenId + ",");
            }
            if (model.NotifyParentFinished != null)
            {
                strSql1.Append("NotifyParentFinished,");
                strSql2.Append("" + model.NotifyParentFinished + ",");
            }
            if (model.OrgUnit != null)
            {
                strSql1.Append("OrgUnit,");
                strSql2.Append("'" + model.OrgUnit + "',");
            }
            if (model.OriginateGroup != null)
            {
                strSql1.Append("OriginateGroup,");
                strSql2.Append("'" + model.OriginateGroup + "',");
            }
            if (model.Originator != null)
            {
                strSql1.Append("Originator,");
                strSql2.Append("'" + model.Originator + "',");
            }
            if (model.ParentActivityName != null)
            {
                strSql1.Append("ParentActivityName,");
                strSql2.Append("'" + model.ParentActivityName + "',");
            }
            if (model.ParentActivityReplyID != null)
            {
                strSql1.Append("ParentActivityReplyID,");
                strSql2.Append("" + model.ParentActivityReplyID + ",");
            }
            if (model.ParentActivityTokenId != null)
            {
                strSql1.Append("ParentActivityTokenId,");
                strSql2.Append("" + model.ParentActivityTokenId + ",");
            }
            if (model.ParentInstanceID != null)
            {
                strSql1.Append("ParentInstanceID,");
                strSql2.Append("'" + model.ParentInstanceID + "',");
            }
            if (model.PlanFinishTime != null)
            {
                strSql1.Append("PlanFinishTime,");
                strSql2.Append("'" + model.PlanFinishTime + "',");
            }
            if (model.Priority != null)
            {
                strSql1.Append("Priority,");
                strSql2.Append("" + model.Priority + ",");
            }
            if (model.Progress != null)
            {
                strSql1.Append("Progress,");
                strSql2.Append("" + model.Progress + ",");
            }
            if (model.Recurrences != null)
            {
                strSql1.Append("Recurrences,");
                strSql2.Append("" + model.Recurrences + ",");
            }
            if (model.RecurrencesRate != null)
            {
                strSql1.Append("RecurrencesRate,");
                strSql2.Append("" + model.RecurrencesRate + ",");
            }
            if (model.SequenceNo != null)
            {
                strSql1.Append("SequenceNo,");
                strSql2.Append("'" + model.SequenceNo + "',");
            }
            if (model.SpsBounded != null)
            {
                strSql1.Append("SpsBounded,");
                strSql2.Append("" + model.SpsBounded + ",");
            }
            if (model.SpsInstanceList != null)
            {
                strSql1.Append("SpsInstanceList,");
                strSql2.Append("'" + model.SpsInstanceList + "',");
            }
            if (model.SpsInstanceListItemId != null)
            {
                strSql1.Append("SpsInstanceListItemId,");
                strSql2.Append("" + model.SpsInstanceListItemId + ",");
            }
            if (model.SpsInstanceSite != null)
            {
                strSql1.Append("SpsInstanceSite,");
                strSql2.Append("'" + model.SpsInstanceSite + "',");
            }
            if (model.SpsInstanceWebName != null)
            {
                strSql1.Append("SpsInstanceWebName,");
                strSql2.Append("'" + model.SpsInstanceWebName + "',");
            }
            if (model.SpsList != null)
            {
                strSql1.Append("SpsList,");
                strSql2.Append("'" + model.SpsList + "',");
            }
            if (model.SpsListItemId != null)
            {
                strSql1.Append("SpsListItemId,");
                strSql2.Append("" + model.SpsListItemId + ",");
            }
            if (model.SpsListItemUrl != null)
            {
                strSql1.Append("SpsListItemUrl,");
                strSql2.Append("'" + model.SpsListItemUrl + "',");
            }
            if (model.SpsSite != null)
            {
                strSql1.Append("SpsSite,");
                strSql2.Append("'" + model.SpsSite + "',");
            }
            if (model.SpsWebName != null)
            {
                strSql1.Append("SpsWebName,");
                strSql2.Append("'" + model.SpsWebName + "',");
            }
            if (model.StartTime != null)
            {
                strSql1.Append("StartTime,");
                strSql2.Append("'" + model.StartTime + "',");
            }
            if (model.State != null)
            {
                strSql1.Append("State,");
                strSql2.Append("" + model.State + ",");
            }
            if (model.Suspended != null)
            {
                strSql1.Append("Suspended,");
                strSql2.Append("" + model.Suspended + ",");
            }
            if (model.TotalCost != null)
            {
                strSql1.Append("TotalCost,");
                strSql2.Append("" + model.TotalCost + ",");
            }
            if (model.TotalCostRate != null)
            {
                strSql1.Append("TotalCostRate,");
                strSql2.Append("" + model.TotalCostRate + ",");
            }
            if (model.UsedTime != null)
            {
                strSql1.Append("UsedTime,");
                strSql2.Append("" + model.UsedTime + ",");
            }
            if (model.UsedTimeRate != null)
            {
                strSql1.Append("UsedTimeRate,");
                strSql2.Append("" + model.UsedTimeRate + ",");
            }
            if (model.UserSuspended != null)
            {
                strSql1.Append("UserSuspended,");
                strSql2.Append("" + model.UserSuspended + ",");
            }
            if (model.WorkflowName != null)
            {
                strSql1.Append("WorkflowName,");
                strSql2.Append("'" + model.WorkflowName + "',");
            }
            if (model.WorkflowPackage != null)
            {
                strSql1.Append("WorkflowPackage,");
                strSql2.Append("'" + model.WorkflowPackage + "',");
            }
            if (model.WorkflowVersion != null)
            {
                strSql1.Append("WorkflowVersion,");
                strSql2.Append("" + model.WorkflowVersion + ",");
            }
            if (model.ExtField_D1 != null)
            {
                strSql1.Append("ExtField_D1,");
                strSql2.Append("'" + model.ExtField_D1 + "',");
            }
            if (model.ExtField_D2 != null)
            {
                strSql1.Append("ExtField_D2,");
                strSql2.Append("'" + model.ExtField_D2 + "',");
            }
            if (model.ExtField_I1 != null)
            {
                strSql1.Append("ExtField_I1,");
                strSql2.Append("" + model.ExtField_I1 + ",");
            }
            if (model.ExtField_I2 != null)
            {
                strSql1.Append("ExtField_I2,");
                strSql2.Append("" + model.ExtField_I2 + ",");
            }
            if (model.ExtField_I3 != null)
            {
                strSql1.Append("ExtField_I3,");
                strSql2.Append("" + model.ExtField_I3 + ",");
            }
            if (model.ExtField_I4 != null)
            {
                strSql1.Append("ExtField_I4,");
                strSql2.Append("" + model.ExtField_I4 + ",");
            }
            if (model.ExtField_I5 != null)
            {
                strSql1.Append("ExtField_I5,");
                strSql2.Append("" + model.ExtField_I5 + ",");
            }
            if (model.ExtField_L1 != null)
            {
                strSql1.Append("ExtField_L1,");
                strSql2.Append("" + model.ExtField_L1 + ",");
            }
            if (model.ExtField_L2 != null)
            {
                strSql1.Append("ExtField_L2,");
                strSql2.Append("" + model.ExtField_L2 + ",");
            }
            if (model.ExtField_S1 != null)
            {
                strSql1.Append("ExtField_S1,");
                strSql2.Append("'" + model.ExtField_S1 + "',");
            }
            if (model.ExtField_S2 != null)
            {
                strSql1.Append("ExtField_S2,");
                strSql2.Append("'" + model.ExtField_S2 + "',");
            }
            if (model.ExtField_S3 != null)
            {
                strSql1.Append("ExtField_S3,");
                strSql2.Append("'" + model.ExtField_S3 + "',");
            }
            if (model.ExtField_S4 != null)
            {
                strSql1.Append("ExtField_S4,");
                strSql2.Append("'" + model.ExtField_S4 + "',");
            }
            if (model.ExtField_S5 != null)
            {
                strSql1.Append("ExtField_S5,");
                strSql2.Append("'" + model.ExtField_S5 + "',");
            }
            if (model.ExtField_S6 != null)
            {
                strSql1.Append("ExtField_S6,");
                strSql2.Append("'" + model.ExtField_S6 + "',");
            }
            if (model.ExtField_S7 != null)
            {
                strSql1.Append("ExtField_S7,");
                strSql2.Append("'" + model.ExtField_S7 + "',");
            }
            if (model.ParentIndex != null)
            {
                strSql1.Append("ParentIndex,");
                strSql2.Append("" + model.ParentIndex + ",");
            }
            if (model.ParentObjectID != null)
            {
                strSql1.Append("ParentObjectID,");
                strSql2.Append("'" + model.ParentObjectID + "',");
            }
            if (model.ParentPropertyName != null)
            {
                strSql1.Append("ParentPropertyName,");
                strSql2.Append("'" + model.ParentPropertyName + "',");
            }
            strSql.Append("insert into SF_InstanceContext(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpEntApp.ExecuteSql(strSql.ToString());
        }


        public int AddWorkItem(SF_WorkItem model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.ObjectID != null)
            {
                strSql1.Append("ObjectID,");
                strSql2.Append("'" + model.ObjectID + "',");
            }
            if (model.ActionName != null)
            {
                strSql1.Append("ActionName,");
                strSql2.Append("'" + model.ActionName + "',");
            }
            if (model.ActivityAssisted != null)
            {
                strSql1.Append("ActivityAssisted,");
                strSql2.Append("" + model.ActivityAssisted + ",");
            }
            if (model.ActivityConsulted != null)
            {
                strSql1.Append("ActivityConsulted,");
                strSql2.Append("" + model.ActivityConsulted + ",");
            }
            if (model.ActivityName != null)
            {
                strSql1.Append("ActivityName,");
                strSql2.Append("'" + model.ActivityName + "',");
            }
            if (model.Approval != null)
            {
                strSql1.Append("Approval,");
                strSql2.Append("" + model.Approval + ",");
            }
            if (model.AssistantFinished != null)
            {
                strSql1.Append("AssistantFinished,");
                strSql2.Append("" + model.AssistantFinished + ",");
            }
            if (model.Assisted != null)
            {
                strSql1.Append("Assisted,");
                strSql2.Append("" + model.Assisted + ",");
            }
            if (model.BatchProcessing != null)
            {
                strSql1.Append("BatchProcessing,");
                strSql2.Append("" + model.BatchProcessing + ",");
            }
            if (model.CanceledByWorkItem != null)
            {
                strSql1.Append("CanceledByWorkItem,");
                strSql2.Append("'" + model.CanceledByWorkItem + "',");
            }
            if (model.CancelTime != null)
            {
                strSql1.Append("CancelTime,");
                strSql2.Append("'" + model.CancelTime + "',");
            }
            if (model.ColorArgb != null)
            {
                strSql1.Append("ColorArgb,");
                strSql2.Append("" + model.ColorArgb + ",");
            }
            if (model.Comment != null)
            {
                strSql1.Append("Comment,");
                strSql2.Append("'" + model.Comment + "',");
            }
            if (model.ConsultantFinished != null)
            {
                strSql1.Append("ConsultantFinished,");
                strSql2.Append("" + model.ConsultantFinished + ",");
            }
            if (model.Consulted != null)
            {
                strSql1.Append("Consulted,");
                strSql2.Append("" + model.Consulted + ",");
            }
            if (model.ConsultedWorkItemID != null)
            {
                strSql1.Append("ConsultedWorkItemID,");
                strSql2.Append("'" + model.ConsultedWorkItemID + "',");
            }
            if (model.Creator != null)
            {
                strSql1.Append("Creator,");
                strSql2.Append("'" + model.Creator + "',");
            }
            if (model.Delegant != null)
            {
                strSql1.Append("Delegant,");
                strSql2.Append("'" + model.Delegant + "',");
            }
            if (model.DisplayName != null)
            {
                strSql1.Append("DisplayName,");
                strSql2.Append("'" + model.DisplayName + "',");
            }
            if (model.EmailApprove != null)
            {
                strSql1.Append("EmailApprove,");
                strSql2.Append("" + model.EmailApprove + ",");
            }
            if (model.FinishAccessPoint != null)
            {
                strSql1.Append("FinishAccessPoint,");
                strSql2.Append("" + model.FinishAccessPoint + ",");
            }
            if (model.Finisher != null)
            {
                strSql1.Append("Finisher,");
                strSql2.Append("'" + model.Finisher + "',");
            }
            if (model.FinishTime != null)
            {
                strSql1.Append("FinishTime,");
                strSql2.Append("'" + model.FinishTime + "',");
            }
            if (model.InstanceId != null)
            {
                strSql1.Append("InstanceId,");
                strSql2.Append("'" + model.InstanceId + "',");
            }
            if (model.ItemFlag != null)
            {
                strSql1.Append("ItemFlag,");
                strSql2.Append("'" + model.ItemFlag + "',");
            }
            if (model.ItemType != null)
            {
                strSql1.Append("ItemType,");
                strSql2.Append("" + model.ItemType + ",");
            }
            if (model.Locked != null)
            {
                strSql1.Append("Locked,");
                strSql2.Append("" + model.Locked + ",");
            }
            if (model.Locker != null)
            {
                strSql1.Append("Locker,");
                strSql2.Append("'" + model.Locker + "',");
            }
            if (model.Locking != null)
            {
                strSql1.Append("Locking,");
                strSql2.Append("" + model.Locking + ",");
            }
            if (model.LongPermittedActions != null)
            {
                strSql1.Append("LongPermittedActions,");
                strSql2.Append("" + model.LongPermittedActions + ",");
            }
            if (model.LongUsedTime != null)
            {
                strSql1.Append("LongUsedTime,");
                strSql2.Append("" + model.LongUsedTime + ",");
            }
            if (model.LongWaitTime != null)
            {
                strSql1.Append("LongWaitTime,");
                strSql2.Append("" + model.LongWaitTime + ",");
            }
            if (model.MonitorAssistant != null)
            {
                strSql1.Append("MonitorAssistant,");
                strSql2.Append("" + model.MonitorAssistant + ",");
            }
            if (model.MonitorConsultant != null)
            {
                strSql1.Append("MonitorConsultant,");
                strSql2.Append("" + model.MonitorConsultant + ",");
            }
            if (model.NotifyFinish != null)
            {
                strSql1.Append("NotifyFinish,");
                strSql2.Append("" + model.NotifyFinish + ",");
            }
            if (model.OrgUnit != null)
            {
                strSql1.Append("OrgUnit,");
                strSql2.Append("'" + model.OrgUnit + "',");
            }
            if (model.Originator != null)
            {
                strSql1.Append("Originator,");
                strSql2.Append("'" + model.Originator + "',");
            }
            if (model.OvertimePolicy != null)
            {
                strSql1.Append("OvertimePolicy,");
                strSql2.Append("" + model.OvertimePolicy + ",");
            }
            if (model.Participant != null)
            {
                strSql1.Append("Participant,");
                strSql2.Append("'" + model.Participant + "',");
            }
            if (model.ParticipateGroup != null)
            {
                strSql1.Append("ParticipateGroup,");
                strSql2.Append("'" + model.ParticipateGroup + "',");
            }
            if (model.PlanFinishTime != null)
            {
                strSql1.Append("PlanFinishTime,");
                strSql2.Append("'" + model.PlanFinishTime + "',");
            }
            if (model.PlanUseTime != null)
            {
                strSql1.Append("PlanUseTime,");
                strSql2.Append("" + model.PlanUseTime + ",");
            }
            if (model.Priority != null)
            {
                strSql1.Append("Priority,");
                strSql2.Append("" + model.Priority + ",");
            }
            if (model.Receiptor != null)
            {
                strSql1.Append("Receiptor,");
                strSql2.Append("'" + model.Receiptor + "',");
            }
            if (model.ReceiveTime != null)
            {
                strSql1.Append("ReceiveTime,");
                strSql2.Append("'" + model.ReceiveTime + "',");
            }
            if (model.ReplyID != null)
            {
                strSql1.Append("ReplyID,");
                strSql2.Append("" + model.ReplyID + ",");
            }
            if (model.SeqNo != null)
            {
                strSql1.Append("SeqNo,");
                strSql2.Append("" + model.SeqNo + ",");
            }
            if (model.SheetAddress != null)
            {
                strSql1.Append("SheetAddress,");
                strSql2.Append("'" + model.SheetAddress + "',");
            }
            if (model.SheetType != null)
            {
                strSql1.Append("SheetType,");
                strSql2.Append("" + model.SheetType + ",");
            }
            if (model.SMSApprove != null)
            {
                strSql1.Append("SMSApprove,");
                strSql2.Append("" + model.SMSApprove + ",");
            }
            if (model.SpsTaskBounded != null)
            {
                strSql1.Append("SpsTaskBounded,");
                strSql2.Append("" + model.SpsTaskBounded + ",");
            }
            if (model.SpsTaskList != null)
            {
                strSql1.Append("SpsTaskList,");
                strSql2.Append("'" + model.SpsTaskList + "',");
            }
            if (model.SpsTaskListItemId != null)
            {
                strSql1.Append("SpsTaskListItemId,");
                strSql2.Append("" + model.SpsTaskListItemId + ",");
            }
            if (model.SpsTaskSite != null)
            {
                strSql1.Append("SpsTaskSite,");
                strSql2.Append("'" + model.SpsTaskSite + "',");
            }
            if (model.SpsTaskWebName != null)
            {
                strSql1.Append("SpsTaskWebName,");
                strSql2.Append("'" + model.SpsTaskWebName + "',");
            }
            if (model.StartTime != null)
            {
                strSql1.Append("StartTime,");
                strSql2.Append("'" + model.StartTime + "',");
            }
            if (model.State != null)
            {
                strSql1.Append("State,");
                strSql2.Append("" + model.State + ",");
            }
            if (model.TokenId != null)
            {
                strSql1.Append("TokenId,");
                strSql2.Append("" + model.TokenId + ",");
            }
            if (model.Urged != null)
            {
                strSql1.Append("Urged,");
                strSql2.Append("" + model.Urged + ",");
            }
            if (model.WorkflowName != null)
            {
                strSql1.Append("WorkflowName,");
                strSql2.Append("'" + model.WorkflowName + "',");
            }
            if (model.WorkflowPackage != null)
            {
                strSql1.Append("WorkflowPackage,");
                strSql2.Append("'" + model.WorkflowPackage + "',");
            }
            if (model.WorkflowVersion != null)
            {
                strSql1.Append("WorkflowVersion,");
                strSql2.Append("" + model.WorkflowVersion + ",");
            }
            if (model.ParentIndex != null)
            {
                strSql1.Append("ParentIndex,");
                strSql2.Append("" + model.ParentIndex + ",");
            }
            if (model.ParentObjectID != null)
            {
                strSql1.Append("ParentObjectID,");
                strSql2.Append("'" + model.ParentObjectID + "',");
            }
            if (model.ParentPropertyName != null)
            {
                strSql1.Append("ParentPropertyName,");
                strSql2.Append("'" + model.ParentPropertyName + "',");
            }
            if (model.ConsultSubject != null)
            {
                strSql1.Append("ConsultSubject,");
                strSql2.Append("'" + model.ConsultSubject + "',");
            }
            if (model.AutoBackActivityName != null)
            {
                strSql1.Append("AutoBackActivityName,");
                strSql2.Append("'" + model.AutoBackActivityName + "',");
            }
            if (model.AutoBackParticipant != null)
            {
                strSql1.Append("AutoBackParticipant,");
                strSql2.Append("'" + model.AutoBackParticipant + "',");
            }
            strSql.Append("insert into SF_WorkItem(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpEntApp.ExecuteSql(strSql.ToString());
        }

        public int AddToken(SF_Token model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.ObjectID != null)
            {
                strSql1.Append("ObjectID,");
                strSql2.Append("'" + model.ObjectID + "',");
            }
            if (model.Activity != null)
            {
                strSql1.Append("Activity,");
                strSql2.Append("'" + model.Activity + "',");
            }
            if (model.Approval != null)
            {
                strSql1.Append("Approval,");
                strSql2.Append("" + model.Approval + ",");
            }
            if (model.CreatedTime != null)
            {
                strSql1.Append("CreatedTime,");
                strSql2.Append("'" + model.CreatedTime + "',");
            }
            if (model.CustomCost1 != null)
            {
                strSql1.Append("CustomCost1,");
                strSql2.Append("" + model.CustomCost1 + ",");
            }
            if (model.CustomCost1Rate != null)
            {
                strSql1.Append("CustomCost1Rate,");
                strSql2.Append("" + model.CustomCost1Rate + ",");
            }
            if (model.CustomCost2 != null)
            {
                strSql1.Append("CustomCost2,");
                strSql2.Append("" + model.CustomCost2 + ",");
            }
            if (model.CustomCost2Rate != null)
            {
                strSql1.Append("CustomCost2Rate,");
                strSql2.Append("" + model.CustomCost2Rate + ",");
            }
            if (model.CustomCost3 != null)
            {
                strSql1.Append("CustomCost3,");
                strSql2.Append("" + model.CustomCost3 + ",");
            }
            if (model.CustomCost3Rate != null)
            {
                strSql1.Append("CustomCost3Rate,");
                strSql2.Append("" + model.CustomCost3Rate + ",");
            }
            if (model.CustomCost4 != null)
            {
                strSql1.Append("CustomCost4,");
                strSql2.Append("" + model.CustomCost4 + ",");
            }
            if (model.CustomCost4Rate != null)
            {
                strSql1.Append("CustomCost4Rate,");
                strSql2.Append("" + model.CustomCost4Rate + ",");
            }
            if (model.CustomCost5 != null)
            {
                strSql1.Append("CustomCost5,");
                strSql2.Append("" + model.CustomCost5 + ",");
            }
            if (model.CustomCost5Rate != null)
            {
                strSql1.Append("CustomCost5Rate,");
                strSql2.Append("" + model.CustomCost5Rate + ",");
            }
            if (model.Descriptions != null)
            {
                strSql1.Append("Descriptions,");
                strSql2.Append("'" + model.Descriptions + "',");
            }
            if (model.Dropped != null)
            {
                strSql1.Append("Dropped,");
                strSql2.Append("" + model.Dropped + ",");
            }
            if (model.Exceptional != null)
            {
                strSql1.Append("Exceptional,");
                strSql2.Append("" + model.Exceptional + ",");
            }
            if (model.FinishedTime != null)
            {
                strSql1.Append("FinishedTime,");
                strSql2.Append("'" + model.FinishedTime + "',");
            }
            if (model.HumanCost != null)
            {
                strSql1.Append("HumanCost,");
                strSql2.Append("" + model.HumanCost + ",");
            }
            if (model.HumanCostRate != null)
            {
                strSql1.Append("HumanCostRate,");
                strSql2.Append("" + model.HumanCostRate + ",");
            }
            if (model.InstanceId != null)
            {
                strSql1.Append("InstanceId,");
                strSql2.Append("'" + model.InstanceId + "',");
            }
            if (model.MachineCost != null)
            {
                strSql1.Append("MachineCost,");
                strSql2.Append("" + model.MachineCost + ",");
            }
            if (model.MachineCostRate != null)
            {
                strSql1.Append("MachineCostRate,");
                strSql2.Append("" + model.MachineCostRate + ",");
            }
            if (model.ManagementCost != null)
            {
                strSql1.Append("ManagementCost,");
                strSql2.Append("" + model.ManagementCost + ",");
            }
            if (model.ManagementCostRate != null)
            {
                strSql1.Append("ManagementCostRate,");
                strSql2.Append("" + model.ManagementCostRate + ",");
            }
            if (model.MaterialCost != null)
            {
                strSql1.Append("MaterialCost,");
                strSql2.Append("" + model.MaterialCost + ",");
            }
            if (model.MaterialCostRate != null)
            {
                strSql1.Append("MaterialCostRate,");
                strSql2.Append("" + model.MaterialCostRate + ",");
            }
            if (model.Retrievable != null)
            {
                strSql1.Append("Retrievable,");
                strSql2.Append("" + model.Retrievable + ",");
            }
            if (model.State != null)
            {
                strSql1.Append("State,");
                strSql2.Append("" + model.State + ",");
            }
            if (model.StrPreTokens != null)
            {
                strSql1.Append("StrPreTokens,");
                strSql2.Append("'" + model.StrPreTokens + "',");
            }
            if (model.TokenId != null)
            {
                strSql1.Append("TokenId,");
                strSql2.Append("" + model.TokenId + ",");
            }
            if (model.TotalCost != null)
            {
                strSql1.Append("TotalCost,");
                strSql2.Append("" + model.TotalCost + ",");
            }
            if (model.TotalCostRate != null)
            {
                strSql1.Append("TotalCostRate,");
                strSql2.Append("" + model.TotalCostRate + ",");
            }
            if (model.UsedTime != null)
            {
                strSql1.Append("UsedTime,");
                strSql2.Append("" + model.UsedTime + ",");
            }
            if (model.UsedTimeRate != null)
            {
                strSql1.Append("UsedTimeRate,");
                strSql2.Append("" + model.UsedTimeRate + ",");
            }
            if (model.ParentIndex != null)
            {
                strSql1.Append("ParentIndex,");
                strSql2.Append("" + model.ParentIndex + ",");
            }
            if (model.ParentObjectID != null)
            {
                strSql1.Append("ParentObjectID,");
                strSql2.Append("'" + model.ParentObjectID + "',");
            }
            if (model.ParentPropertyName != null)
            {
                strSql1.Append("ParentPropertyName,");
                strSql2.Append("'" + model.ParentPropertyName + "',");
            }
            strSql.Append("insert into SF_Token(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpEntApp.ExecuteSql(strSql.ToString());
        }

        public int AddOpinionAttachment(MP_OpinionAttachment model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.Id != null)
            {
                strSql1.Append("Id,");
                strSql2.Append("'" + model.Id + "',");
            }
            if (model.InstanceId != null)
            {
                strSql1.Append("InstanceId,");
                strSql2.Append("'" + model.InstanceId + "',");
            }
            if (model.SubInstanceId != null)
            {
                strSql1.Append("SubInstanceId,");
                strSql2.Append("'" + model.SubInstanceId + "',");
            }
            if (model.WorkItemId != null)
            {
                strSql1.Append("WorkItemId,");
                strSql2.Append("'" + model.WorkItemId + "',");
            }
            if (model.FileId != null)
            {
                strSql1.Append("FileId,");
                strSql2.Append("'" + model.FileId + "',");
            }
            if (model.FileName != null)
            {
                strSql1.Append("FileName,");
                strSql2.Append("'" + model.FileName + "',");
            }
            if (model.Activity != null)
            {
                strSql1.Append("Activity,");
                strSql2.Append("'" + model.Activity + "',");
            }
            if (model.Action != null)
            {
                strSql1.Append("Action,");
                strSql2.Append("'" + model.Action + "',");
            }
            if (model.Text != null)
            {
                strSql1.Append("Text,");
                strSql2.Append("'" + model.Text + "',");
            }
            if (model.UserId != null)
            {
                strSql1.Append("UserId,");
                strSql2.Append("'" + model.UserId + "',");
            }
            if (model.UserLevel != null)
            {
                strSql1.Append("UserLevel,");
                strSql2.Append("'" + model.UserLevel + "',");
            }
            if (model.DeptId != null)
            {
                strSql1.Append("DeptId,");
                strSql2.Append("'" + model.DeptId + "',");
            }
            if (model.DeptName != null)
            {
                strSql1.Append("DeptName,");
                strSql2.Append("'" + model.DeptName + "',");
            }
            if (model.CreatedTime != null)
            {
                strSql1.Append("CreatedTime,");
                strSql2.Append("'" + model.CreatedTime + "',");
            }
            if (model.ModifiedBy != null)
            {
                strSql1.Append("ModifiedBy,");
                strSql2.Append("'" + model.ModifiedBy + "',");
            }
            if (model.State != null)
            {
                strSql1.Append("State,");
                strSql2.Append("'" + model.State + "',");
            }
            strSql.Append("insert into MP_OpinionAttachment(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpIcanYunPan.ExecuteSql(strSql.ToString());
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddFlow(MP_Flow model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.Id != null)
            {
                strSql1.Append("Id,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.InstanceId != null)
            {
                strSql1.Append("InstanceId,");
                strSql2.Append("'" + model.InstanceId + "',");
            }
            if (model.WorkItemId != null)
            {
                strSql1.Append("WorkItemId,");
                strSql2.Append("'" + model.WorkItemId + "',");
            }
            if (model.CurrentNode != null)
            {
                strSql1.Append("CurrentNode,");
                strSql2.Append("'" + model.CurrentNode + "',");
            }
            if (model.UserId != null)
            {
                strSql1.Append("UserId,");
                strSql2.Append("'" + model.UserId + "',");
            }
            if (model.CurrentAction != null)
            {
                strSql1.Append("CurrentAction,");
                strSql2.Append("'" + model.CurrentAction + "',");
            }
            if (model.CurrentActionOption != null)
            {
                strSql1.Append("CurrentActionOption,");
                strSql2.Append("'" + model.CurrentActionOption + "',");
            }
            if (model.CurrentParticipant != null)
            {
                strSql1.Append("CurrentParticipant,");
                strSql2.Append("'" + model.CurrentParticipant + "',");
            }
            if (model.NextNode != null)
            {
                strSql1.Append("NextNode,");
                strSql2.Append("'" + model.NextNode + "',");
            }
            if (model.NextAction != null)
            {
                strSql1.Append("NextAction,");
                strSql2.Append("'" + model.NextAction + "',");
            }
            if (model.NextActionType != null)
            {
                strSql1.Append("NextActionType,");
                strSql2.Append("'" + model.NextActionType + "',");
            }
            if (model.NextParticipants != null)
            {
                strSql1.Append("NextParticipants,");
                strSql2.Append("'" + model.NextParticipants + "',");
            }
            if (model.CreateDate != null)
            {
                strSql1.Append("CreateDate,");
                strSql2.Append("'" + model.CreateDate + "',");
            }
            if (model.Type != null)
            {
                strSql1.Append("Type,");
                strSql2.Append("'" + model.Type + "',");
            }
            strSql.Append("insert into MP_Flow(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpIcanYunPan.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddMessage(MP_Message model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.Id != null)
            {
                strSql1.Append("Id,");
                strSql2.Append("'" + model.Id + "',");
            }
            if (model.MsgType != null)
            {
                strSql1.Append("MsgType,");
                strSql2.Append("'" + model.MsgType + "',");
            }
            if (model.Status != null)
            {
                strSql1.Append("Status,");
                strSql2.Append("'" + model.Status + "',");
            }
            if (model.Title != null)
            {
                strSql1.Append("Title,");
                strSql2.Append("'" + model.Title + "',");
            }
            if (model.Contents != null)
            {
                strSql1.Append("Contents,");
                strSql2.Append("'" + model.Contents + "',");
            }
            if (model.CurrParticipants != null)
            {
                strSql1.Append("CurrParticipants,");
                strSql2.Append("'" + model.CurrParticipants + "',");
            }
            if (model.UserId != null)
            {
                strSql1.Append("UserId,");
                strSql2.Append("'" + model.UserId + "',");
            }
            if (model.InstanceId != null)
            {
                strSql1.Append("InstanceId,");
                strSql2.Append("'" + model.InstanceId + "',");
            }
            if (model.AppId != null)
            {
                strSql1.Append("AppId,");
                strSql2.Append("'" + model.AppId + "',");
            }
            if (model.AppName != null)
            {
                strSql1.Append("AppName,");
                strSql2.Append("'" + model.AppName + "',");
            }
            if (model.ListId != null)
            {
                strSql1.Append("ListId,");
                strSql2.Append("'" + model.ListId + "',");
            }
            if (model.MPListId != null)
            {
                strSql1.Append("MPListId,");
                strSql2.Append("'" + model.MPListId + "',");
            }
            if (model.FormCode != null)
            {
                strSql1.Append("FormCode,");
                strSql2.Append("'" + model.FormCode + "',");
            }
            if (model.FormDataId != null)
            {
                strSql1.Append("FormDataId,");
                strSql2.Append("'" + model.FormDataId + "',");
            }
            if (model.ParticipantsId != null)
            {
                strSql1.Append("ParticipantsId,");
                strSql2.Append("'" + model.ParticipantsId + "',");
            }
            if (model.CreatedDate != null)
            {
                strSql1.Append("CreatedDate,");
                strSql2.Append("'" + model.CreatedDate + "',");
            }
            if (model.CreatedBy != null)
            {
                strSql1.Append("CreatedBy,");
                strSql2.Append("'" + model.CreatedBy + "',");
            }
            if (model.UpdatedDate != null)
            {
                strSql1.Append("UpdatedDate,");
                strSql2.Append("'" + model.UpdatedDate + "',");
            }
            if (model.UpdatedBy != null)
            {
                strSql1.Append("UpdatedBy,");
                strSql2.Append("'" + model.UpdatedBy + "',");
            }
            if (model.ToUserId != null)
            {
                strSql1.Append("ToUserId,");
                strSql2.Append("'" + model.ToUserId + "',");
            }
            if (model.ToUserName != null)
            {
                strSql1.Append("ToUserName,");
                strSql2.Append("'" + model.ToUserName + "',");
            }
            if (model.LinkUrl != null)
            {
                strSql1.Append("LinkUrl,");
                strSql2.Append("'" + model.LinkUrl + "',");
            }
            if (model.WorkItemId != null)
            {
                strSql1.Append("WorkItemId,");
                strSql2.Append("'" + model.WorkItemId + "',");
            }
            if (model.WFStatus != null)
            {
                strSql1.Append("WFStatus,");
                strSql2.Append("" + model.WFStatus + ",");
            }
            if (model.WorkflowName != null)
            {
                strSql1.Append("WorkflowName,");
                strSql2.Append("'" + model.WorkflowName + "',");
            }
            if (model.PackageName != null)
            {
                strSql1.Append("PackageName,");
                strSql2.Append("'" + model.PackageName + "',");
            }
            if (model.Delegant != null)
            {
                strSql1.Append("Delegant,");
                strSql2.Append("'" + model.Delegant + "',");
            }
            if (model.UserName != null)
            {
                strSql1.Append("UserName,");
                strSql2.Append("'" + model.UserName + "',");
            }
            if (model.WorkflowTitle != null)
            {
                strSql1.Append("WorkflowTitle,");
                strSql2.Append("'" + model.WorkflowTitle + "',");
            }
            strSql.Append("insert into MP_Message(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpIcanYunPan.ExecuteSql(strSql.ToString());
        }


        public int Add物品领用申请子表(BD_119_物品领用申请子表 model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.Id != null)
            {
                strSql1.Append("Id,");
                strSql2.Append("'" + model.Id + "',");
            }
            if (model.物品名称 != null)
            {
                strSql1.Append("物品名称,");
                strSql2.Append("'" + model.物品名称 + "',");
            }
            if (model.规格 != null)
            {
                strSql1.Append("规格,");
                strSql2.Append("'" + model.规格 + "',");
            }
            if (model.数量 != null)
            {
                strSql1.Append("数量,");
                strSql2.Append("" + model.数量 + ",");
            }
            if (model.计量单位 != null)
            {
                strSql1.Append("计量单位,");
                strSql2.Append("'" + model.计量单位 + "',");
            }
            if (model.操作 != null)
            {
                strSql1.Append("操作,");
                strSql2.Append("'" + model.操作 + "',");
            }
            if (model.form_id != null)
            {
                strSql1.Append("form_id,");
                strSql2.Append("'" + model.form_id + "',");
            }
            if (model.formcode != null)
            {
                strSql1.Append("formcode,");
                strSql2.Append("'" + model.formcode + "',");
            }
            if (model.formfile != null)
            {
                strSql1.Append("formfile,");
                strSql2.Append("'" + model.formfile + "',");
            }
            if (model.formimg != null)
            {
                strSql1.Append("formimg,");
                strSql2.Append("'" + model.formimg + "',");
            }
            if (model.relcode != null)
            {
                strSql1.Append("relcode,");
                strSql2.Append("'" + model.relcode + "',");
            }
            if (model.pid != null)
            {
                strSql1.Append("pid,");
                strSql2.Append("'" + model.pid + "',");
            }
            if (model.flag != null)
            {
                strSql1.Append("flag,");
                strSql2.Append("'" + model.flag + "',");
            }
            if (model.form_category != null)
            {
                strSql1.Append("form_category,");
                strSql2.Append("'" + model.form_category + "',");
            }
            if (model.instanceId != null)
            {
                strSql1.Append("instanceId,");
                strSql2.Append("'" + model.instanceId + "',");
            }
            if (model.workItemId != null)
            {
                strSql1.Append("workItemId,");
                strSql2.Append("'" + model.workItemId + "',");
            }
            if (model.packageName != null)
            {
                strSql1.Append("packageName,");
                strSql2.Append("'" + model.packageName + "',");
            }
            if (model.workflowName != null)
            {
                strSql1.Append("workflowName,");
                strSql2.Append("'" + model.workflowName + "',");
            }
            if (model.packageTitle != null)
            {
                strSql1.Append("packageTitle,");
                strSql2.Append("'" + model.packageTitle + "',");
            }
            if (model.workflowTitle != null)
            {
                strSql1.Append("workflowTitle,");
                strSql2.Append("'" + model.workflowTitle + "',");
            }
            if (model.issave != null)
            {
                strSql1.Append("issave,");
                strSql2.Append("'" + model.issave + "',");
            }
            if (model.useraccount != null)
            {
                strSql1.Append("useraccount,");
                strSql2.Append("'" + model.useraccount + "',");
            }
            if (model.updateuseraccount != null)
            {
                strSql1.Append("updateuseraccount,");
                strSql2.Append("'" + model.updateuseraccount + "',");
            }
            if (model.rel_id != null)
            {
                strSql1.Append("rel_id,");
                strSql2.Append("'" + model.rel_id + "',");
            }
            if (model.namefullpath != null)
            {
                strSql1.Append("namefullpath,");
                strSql2.Append("'" + model.namefullpath + "',");
            }
            if (model.idfullpath != null)
            {
                strSql1.Append("idfullpath,");
                strSql2.Append("'" + model.idfullpath + "',");
            }
            if (model.userorganization != null)
            {
                strSql1.Append("userorganization,");
                strSql2.Append("'" + model.userorganization + "',");
            }
            if (model.relselect != null)
            {
                strSql1.Append("relselect,");
                strSql2.Append("'" + model.relselect + "',");
            }
            if (model.formversionid != null)
            {
                strSql1.Append("formversionid,");
                strSql2.Append("'" + model.formversionid + "',");
            }
            if (model.SequenceNo != null)
            {
                strSql1.Append("SequenceNo,");
                strSql2.Append("'" + model.SequenceNo + "',");
            }
            if (model.ParticipantsInfo != null)
            {
                strSql1.Append("ParticipantsInfo,");
                strSql2.Append("'" + model.ParticipantsInfo + "',");
            }
            if (model.ParticipantsId != null)
            {
                strSql1.Append("ParticipantsId,");
                strSql2.Append("'" + model.ParticipantsId + "',");
            }
            if (model.OriginatorDeptName != null)
            {
                strSql1.Append("OriginatorDeptName,");
                strSql2.Append("'" + model.OriginatorDeptName + "',");
            }
            if (model.OriginatorDeptId != null)
            {
                strSql1.Append("OriginatorDeptId,");
                strSql2.Append("'" + model.OriginatorDeptId + "',");
            }
            if (model.ToParticipantsInfo != null)
            {
                strSql1.Append("ToParticipantsInfo,");
                strSql2.Append("'" + model.ToParticipantsInfo + "',");
            }
            if (model.ToParticipantsId != null)
            {
                strSql1.Append("ToParticipantsId,");
                strSql2.Append("'" + model.ToParticipantsId + "',");
            }
            if (model.HasParticipantsInfo != null)
            {
                strSql1.Append("HasParticipantsInfo,");
                strSql2.Append("'" + model.HasParticipantsInfo + "',");
            }
            if (model.HasParticipantsId != null)
            {
                strSql1.Append("HasParticipantsId,");
                strSql2.Append("'" + model.HasParticipantsId + "',");
            }
            if (model.createtime != null)
            {
                strSql1.Append("createtime,");
                strSql2.Append("'" + model.createtime + "',");
            }
            if (model.username != null)
            {
                strSql1.Append("username,");
                strSql2.Append("'" + model.username + "',");
            }
            if (model.userid != null)
            {
                strSql1.Append("userid,");
                strSql2.Append("'" + model.userid + "',");
            }
            if (model.orgname != null)
            {
                strSql1.Append("orgname,");
                strSql2.Append("'" + model.orgname + "',");
            }
            if (model.orgid != null)
            {
                strSql1.Append("orgid,");
                strSql2.Append("'" + model.orgid + "',");
            }
            if (model.updatetime != null)
            {
                strSql1.Append("updatetime,");
                strSql2.Append("'" + model.updatetime + "',");
            }
            if (model.updateusername != null)
            {
                strSql1.Append("updateusername,");
                strSql2.Append("'" + model.updateusername + "',");
            }
            if (model.updateuserid != null)
            {
                strSql1.Append("updateuserid,");
                strSql2.Append("'" + model.updateuserid + "',");
            }
            if (model.updateorgname != null)
            {
                strSql1.Append("updateorgname,");
                strSql2.Append("'" + model.updateorgname + "',");
            }
            if (model.updateorgid != null)
            {
                strSql1.Append("updateorgid,");
                strSql2.Append("'" + model.updateorgid + "',");
            }
            strSql.Append("insert into BD_119_物品领用申请子表(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelpIcanYunPan.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddAmendantRecord(AmendantRecord model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.AmendantRecordID != null)
            {
                strSql1.Append("AmendantRecordID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.strxgr != null)
            {
                strSql1.Append("strxgr,");
                strSql2.Append("'" + model.strxgr + "',");
            }
            if (model.strxgms != null)
            {
                strSql1.Append("strxgms,");
                strSql2.Append("'" + model.strxgms + "',");
            }
            if (model.strxgsj != null)
            {
                strSql1.Append("strxgsj,");
                strSql2.Append("'" + model.strxgsj + "',");
            }
            if (model.strip != null)
            {
                strSql1.Append("strip,");
                strSql2.Append("'" + model.strip + "',");
            }
            strSql.Append("insert into AmendantRecord(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelp.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddAssociatedDocument(AssociatedDocument model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.AssociatedDocumentID != null)
            {
                strSql1.Append("AssociatedDocumentID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.strText != null)
            {
                strSql1.Append("strText,");
                strSql2.Append("'" + model.strText + "',");
            }
            if (model.strUnid != null)
            {
                strSql1.Append("strUnid,");
                strSql2.Append("'" + model.strUnid + "',");
            }
            if (model.strDbPath != null)
            {
                strSql1.Append("strDbPath,");
                strSql2.Append("'" + model.strDbPath + "',");
            }
            strSql.Append("insert into AssociatedDocument(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelp.ExecuteSql(strSql.ToString());
        }


        public int AddEvaluationDocument(EvaluationDocument model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.EvaluationDocumentID != null)
            {
                strSql1.Append("EvaluationDocumentID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.strzjdf != null)
            {
                strSql1.Append("strzjdf,");
                strSql2.Append("'" + model.strzjdf + "',");
            }
            if (model.strkfxm != null)
            {
                strSql1.Append("strkfxm,");
                strSql2.Append("'" + model.strkfxm + "',");
            }
            strSql.Append("insert into EvaluationDocument(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelp.ExecuteSql(strSql.ToString());
        }

        public int AddReminderLog(ReminderLog model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.ReminderLogID != null)
            {
                strSql1.Append("ReminderLogID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.strnr != null)
            {
                strSql1.Append("strnr,");
                strSql2.Append("'" + model.strnr + "',");
            }
            if (model.stryh != null)
            {
                strSql1.Append("stryh,");
                strSql2.Append("'" + model.stryh + "',");
            }
            if (model.strsj != null)
            {
                strSql1.Append("strsj,");
                strSql2.Append("'" + model.strsj + "',");
            }
            strSql.Append("insert into ReminderLog(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelp.ExecuteSql(strSql.ToString());
        }

        public int AddNotificationLog(NotificationLog model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.NotificationLogID != null)
            {
                strSql1.Append("NotificationLogID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.strzhfsr != null)
            {
                strSql1.Append("strzhfsr,");
                strSql2.Append("'" + model.strzhfsr + "',");
            }
            if (model.strzhfssj != null)
            {
                strSql1.Append("strzhfssj,");
                strSql2.Append("'" + model.strzhfssj + "',");
            }
            if (model.strzhjsr != null)
            {
                strSql1.Append("strzhjsr,");
                strSql2.Append("'" + model.strzhjsr + "',");
            }
            if (model.strzhydsj != null)
            {
                strSql1.Append("strzhydsj,");
                strSql2.Append("'" + model.strzhydsj + "',");
            }
            if (model.strzhydzt != null)
            {
                strSql1.Append("strzhydzt,");
                strSql2.Append("'" + model.strzhydzt + "',");
            }
            strSql.Append("insert into NotificationLog(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelp.ExecuteSql(strSql.ToString());
        }


        public int AddDispatchTracking(DispatchTracking model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.DispatchTrackingID != null)
            {
                strSql1.Append("DispatchTrackingID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.DocumentID != null)
            {
                strSql1.Append("DocumentID,");
                strSql2.Append("'" + model.DocumentID + "',");
            }
            if (model.strjsbm != null)
            {
                strSql1.Append("strjsbm,");
                strSql2.Append("'" + model.strjsbm + "',");
            }
            if (model.strjsr != null)
            {
                strSql1.Append("strjsr,");
                strSql2.Append("'" + model.strjsr + "',");
            }
            if (model.strjszt != null)
            {
                strSql1.Append("strjszt,");
                strSql2.Append("'" + model.strjszt + "',");
            }
            if (model.strjssj != null)
            {
                strSql1.Append("strjssj,");
                strSql2.Append("'" + model.strjssj + "',");
            }
            strSql.Append("insert into DispatchTracking(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return sqlHelp.ExecuteSql(strSql.ToString());
        }

        public int InsertCancellationDocument(string unid)
        {
            string sql = "insert into [dbo].[CancellationDocument] values ('" + unid + "')";
            return sqlHelp.ExecuteSql(sql);
        }

    }
}
